package com.example.weathermvvm.ui

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import com.example.weathermvvm.R
import com.example.weathermvvm.ui.area.ChooseAreaFragment
import com.example.weathermvvm.ui.area.ChooseAreaViewModel
import com.example.weathermvvm.ui.weather.WeatherActivity
import com.example.weathermvvm.util.InjectorUtil

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val viewModel:MainModel by viewModels {
            InjectorUtil.getMainModelFactory()
        }
        if (viewModel.isWeatherCached()){
            startActivity(Intent(this,WeatherActivity::class.java))
            finish()
        }else{
            supportFragmentManager.beginTransaction().replace(R.id.container,ChooseAreaFragment()).commit()
        }
    }
}